#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QStateMachine>
#include <QFinalState>
#include "ewha.h"
#include "ConsoleWrapper.h"
#include "windows.h"

namespace Ui {
class MainWindow;
}

enum EAction
{
	eActPatient, eActCapture, eActSave, eActDiagnosis,
	eActDraw, eActHistorgam, eActProfile, eActWindowing, eActGamma
};

enum EMSG
{
	eMSGStandby, eMSGStandbyDone, eMSGReady, eMSGReadyDone, eMSGEXPOON, eMSGEXPOOFF, eMSGIMGDone, eMSGClose, eMSGError
};

class MainWindow : public QMainWindow
{
	Q_OBJECT

public:
	explicit MainWindow(QWidget *parent = 0);
	~MainWindow();

signals:
	void SignalSetTool(ETool eTool);

protected:
	bool nativeEvent(const QByteArray &eventType, void *message, long *result);

private:
	void initStateMachine();
	void connectSignalSlot();
	void changeStackMainIndex(int);
	void changeStackLargeWorkareaIndex(int);
	void changeStackSmallWorkareaIndex(int);

private slots:
	void SlotChangeModStart();
	void SlotChangeModSearchRegister();
	void SlotChangeModSearchResult();
	void SlotChangeModCapturedateList();
	void SlotChangeModViewImage();
	void SlotChangeModWindowingTool();
	void SlotChangeModDrawTool();
	void SlotChangeModGammaTool();
	void SlotChangeModHistogramTool();
	void SlotChangeModProfileTool();
	void SlotChangeModConfigCapture();
	void SlotChangeModPreviewCapture();

	void SlotSearchPatient(SPatient &patient);
	void SlotRegisterPatient(SPatient &patient);
	void SlotSelectedPatient(int iPatientID);
	void SlotSelectCaptureDate(QDate dateCapture);
	void SlotNewCapture();
	void SlotJustCaptured(const QString &strFilePath);
	void SlotSelectedTeeth(int iTeethIndex);
	void SlotCaptureProcessEnd();
	void SlotCaptureMore();
	void SlotConfig();
	void SlotHistory(QAction *pUndo, QAction *pRedo);
	void SlotDiagnosis();
	void SlotMessage(const QString &strMessage);
	void SlotStartConsole();
	void SlotSendStandby();
	void SlotSendReady();
	void SlotSendClose();
	void SlotControlValue(int iVoltage, int iCurrent, int iTime);

private:
	void searchPatient(SPatient &patient);
	bool registerPatient(SPatient &patient) const;
	bool existPatient(const SPatient &patient) const;
	void setActionEnable(QList<EAction>);
	void setActionEnableAll();
	void setActionDisable(QList<EAction>);
	void registerMessage();
	void makeActionList();

private:
	Ui::MainWindow *ui;
	QStateMachine *m_pStateMachine;
	QState *m_pStateInitial, *m_pStatePatient;
	QFinalState *m_pStateFinal;
	int m_iPatientID;
	int m_iTeethPosition;
	QString m_strCaptureFilePath;
	QList<QAction*> m_listAct;
	QWidget *m_pProgressWidget;
	QProcess m_procOSK;
	ConsoleWrapper *m_pConsole;
	uint m_msgID[9];
	int m_iVoltage;
	int m_iCurrent;
	int m_iTime;
};

#endif // MAINWINDOW_H
